<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <%- include conmon %>
</head>
<body>
    <!-- 头部结构 -->
    <%- include('header',{title:'my'}) %>

    <h2 class="text-primary">个人中心--(用户名：<%- result.username %>)  </h2>
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-4">
                <form>
                    <div class="form-group">
                        <label for="username">用户名</label>
                        <input disabled type="text" value="<%- result.username %>" name="username" class="form-control" id="username" placeholder="请输入用户名">
                    </div>
                    <div class="form-group">
                        <label for="nickname">昵称</label>
                        <input name="nickname" value="<%- result.nickname %>" type="text" class="form-control" id="nickname" placeholder="请输入昵称">
                    </div>
                    <div class="form-group">
                        <label for="age">年龄</label>
                        <input name="age"  value="<%- result.age %>" type="number" class="form-control" id="age" placeholder="请输入年龄">
                    </div>
                    <div class="form-group">
                        <label for="email">邮箱</label>
                        <input name="email"  value="<%- result.email %>" type="email" class="form-control" id="email" placeholder="请输入邮箱">
                    </div>
                </form>
                <!-- button 写下form外面 -->
                <button type="button" onclick="changeinfo()" class="btn btn-info">修改信息</button>
                <button type="button" onclick="location.href='/resetpwd'" class="btn btn-danger">重置密码</button>
            </div>
        </div>

    <!-- 尾部结构 -->
    <%- include footer %>

    <!-- 利用ajax传数据，修改信息 -->
    <script>
        function changeinfo(){
            $.ajax({
                url:'/users/changeinfo',
                type:'POST',
                data:{
                    nickname:$('#nickname').val(),
                    age:$('#age').val(),
                    email:$('#email').val()
                }
            }).then(res=>{
                console.log(res);
                if(res.code === 200){
                    location.href="/my";//刷新页面
                }else{
                    alert("修改页面失败");
                }
            });
        }
    </script>


</body>
</html>




